home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / text_utl / vuestr / viewer.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-22  |  10.0 KB  |  292 lines

  1. VERSION 2.00
  2. Begin Form Viewer 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "VBstrAPI Huge Array Viewer Demo"
  5.    ClientHeight    =   3615
  6.    ClientLeft      =   540
  7.    ClientTop       =   2175
  8.    ClientWidth     =   7575
  9.    Height          =   4305
  10.    Left            =   480
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3615
  13.    ScaleWidth      =   7575
  14.    Top             =   1545
  15.    Width           =   7695
  16.    Begin PictureBox InfoBar 
  17.       Align           =   1  'Align Top
  18.       BackColor       =   &H00C0C0C0&
  19.       Height          =   330
  20.       Left            =   0
  21.       ScaleHeight     =   300
  22.       ScaleWidth      =   7545
  23.       TabIndex        =   1
  24.       Top             =   0
  25.       Width           =   7575
  26.       Begin Label Status 
  27.          BackStyle       =   0  'Transparent
  28.          FontBold        =   -1  'True
  29.          FontItalic      =   0   'False
  30.          FontName        =   "Arial"
  31.          FontSize        =   8.25
  32.          FontStrikethru  =   0   'False
  33.          FontUnderline   =   0   'False
  34.          ForeColor       =   &H00800000&
  35.          Height          =   270
  36.          Left            =   120
  37.          TabIndex        =   2
  38.          Top             =   45
  39.          Width           =   3195
  40.       End
  41.    End
  42.    Begin CommonDialog CMDialog1 
  43.       Left            =   60
  44.       Top             =   2025
  45.    End
  46.    Begin TextBox MainView 
  47.       BackColor       =   &H00C0C0C0&
  48.       FontBold        =   0   'False
  49.       FontItalic      =   0   'False
  50.       FontName        =   "Courier New"
  51.       FontSize        =   9.75
  52.       FontStrikethru  =   0   'False
  53.       FontUnderline   =   0   'False
  54.       Height          =   2565
  55.       Left            =   570
  56.       MultiLine       =   -1  'True
  57.       ScrollBars      =   3  'Both
  58.       TabIndex        =   0
  59.       TabStop         =   0   'False
  60.       Tag             =   "OL"
  61.       Top             =   570
  62.       Width           =   4935
  63.    End
  64.    Begin Menu mnuFile 
  65.       Caption         =   "&File"
  66.       Begin Menu mnuFileOpen 
  67.          Caption         =   "&Open"
  68.       End
  69.       Begin Menu mnuFileExit 
  70.          Caption         =   "&Exit"
  71.       End
  72.    End
  73.    Begin Menu mnuFirst 
  74.       Caption         =   "&First Page"
  75.    End
  76.    Begin Menu mnuPrev 
  77.       Caption         =   "&Prev Page"
  78.    End
  79.    Begin Menu mnuNext 
  80.       Caption         =   "&Next Page"
  81.    End
  82.    Begin Menu mnuLast 
  83.       Caption         =   "&Last Page"
  84.    End
  85.    Begin Menu mnuAbout 
  86.       Caption         =   "&About"
  87.    End
  88. Option Explicit
  89. Const BUFFER_SIZE = 32768
  90. Dim SHandle     As Long     ' ArrayStr Handle
  91. Dim SPages      As Integer  ' String Pages Used
  92. Dim CHandle     As Long     ' CatStr Handle
  93. Dim CurrentPage As Integer  ' Currently displayed page
  94. Sub About ()
  95.     MsgBox "This program demonstrates a method of viewing large text files.  This demo does not attempt to demonstrate editing techniques.  That will be covered in another demo." + Chr$(10) + "" + Chr$(10) + "VBstrAPI.DLL Copyright " & Chr(169) & " 1995, Greg Truesdell", 64, "VBstrAPI Viewer Demonstration"
  96. End Sub
  97. Sub Form_Activate ()
  98.     About
  99. End Sub
  100. Sub Form_Load ()
  101.     SHandle = -1
  102.     CHandle = CreateNewCatString(BUFFER_SIZE)
  103.     If CHandle = -1 Then
  104.     MsgBox "The program was unable to create a CatStr Object." + Chr$(10) + "This usually means there is not enough memory.", 16, "Unable to Continue"
  105.     Unload Me
  106.     End If
  107.     ' setting page to zero resets the menu
  108.     SetCurrentPage 0
  109.     Me.Width = screen.Width * .8
  110.     Me.Left = screen.Width * .1
  111.     Me.Top = screen.Height * .1
  112.     Me.Height = screen.Height * .8
  113. End Sub
  114. Sub Form_Paint ()
  115.     Outlines Me
  116. End Sub
  117. Sub Form_Resize ()
  118.     On Error Resume Next
  119.     MainView.Left = 120
  120.     MainView.Top = InfoBar.Height + 120
  121.     MainView.Width = ScaleWidth - 240
  122.     MainView.Height = ScaleHeight - 240 - InfoBar.Height
  123.     On Error GoTo 0
  124. End Sub
  125. Sub Form_Unload (Cancel As Integer)
  126.     If CHandle > -1 Then DestroyCatString CHandle
  127.     If SHandle > -1 Then DestroyStringArray SHandle
  128. End Sub
  129. Sub mnuAbout_Click ()
  130.     About
  131. End Sub
  132. Sub mnuFileExit_Click ()
  133.     Unload Me
  134. End Sub
  135. '=============================================================
  136. '=  Created:    05/20/95 at 09:59 AM
  137. '=  Project:    VIEWSTR.MAK
  138. '=  Author:     Greg Truesdell
  139. '=============================================================
  140. '=  Purpose:    Open and Read a File into a ArrayStr Array.
  141. '=  Parameters: None.
  142. '=  Returns:    ArrayStr associated with the global SHandle
  143. '=              variable is loaded with the contents of the
  144. '=              the file.  The global SPages variable is
  145. '=              updated with the count of ArrayStr elements
  146. '=              containing text.
  147. '=============================================================
  148. Sub mnuFileOpen_Click ()
  149.   Dim CFilename As String   ' the file to open
  150.   Dim File      As Integer  ' the file handle
  151.   Dim FLen      As Long     ' the file length
  152.   Dim PageGuess As Integer  ' best guess at size of array
  153.   Dim Text      As String   ' a line of text
  154.   Dim rc        As Integer  ' generic return code
  155.     On Error GoTo OpenCancel
  156.     CMDialog1.DialogTitle = "Open Text File for Viewing"
  157.     CMDialog1.Filename = ""
  158.     CMDialog1.InitDir = ""
  159.     CMDialog1.Filter = "All Files (*.*)|*.*|"
  160.     CMDialog1.FilterIndex = 1
  161.     CMDialog1.MaxFileSize = 256
  162.     CMDialog1.DefaultExt = "*.*"
  163.     CMDialog1.HelpFile = ""
  164.     CMDialog1.HelpCommand = &H1
  165.     CMDialog1.HelpContext = 0
  166.     CMDialog1.CancelError = True
  167.     CMDialog1.Flags = 22540
  168.     CMDialog1.Action = 1
  169.     On Error GoTo OpenError
  170.     CFilename = CMDialog1.Filename
  171.     FLen = FileLen(CFilename)
  172.     ' ignore empty files
  173.     If FLen = 0 Then
  174.     MsgBox "The file '" & CFilename & "' is empty.", 64, "File Empty"
  175.     GoTo OpenExit
  176.     End If
  177.     ' now, open the file
  178.     File = FreeFile
  179.     Open CFilename For Input As #File
  180.     On Error GoTo ReadError
  181.     ' start with a new string array
  182.     If SHandle > -1 Then DestroyStringArray SHandle
  183.     ' estimate the size of array required, then add 1 more element
  184.     PageGuess = (FLen / BUFFER_SIZE) + 1
  185.     PageGuess = PageGuess + 1
  186.     ' create the array, exit on error
  187.     SHandle = CreateNewStringArray(PageGuess, BUFFER_SIZE)
  188.     If SHandle = -1 Then
  189.     MsgBox "Unable to allocate an ArrayStr large enough to contain the file.", 16, "ArrayStr Creation Error"
  190.     GoTo OpenExit
  191.     End If
  192.     ' read the file
  193.     ' this method of reading files is slow, but we need to do
  194.     ' it this way for files larger than one array element
  195.     SPages = 0
  196.     CatStrClear CHandle
  197.     Me.MousePointer = 11
  198.     Do While Not EOF(File)
  199.     Line Input #File, Text
  200.     rc = CatStrAddLine(CHandle, Text)
  201.     If rc = -1 Then ' CatStr is full.
  202.         rc = PutArrayStr(SHandle, SPages, CatStrCopy(CHandle))
  203.         CatStrClear CHandle
  204.         SPages = SPages + 1
  205.     End If
  206.     Loop
  207.     ' don't forget to pickup the last bit.
  208.     If CatStrLength(CHandle) > 0 Then
  209.     rc = PutArrayStr(SHandle, SPages, CatStrCopy(CHandle))
  210.     CatStrClear CHandle
  211.     SPages = SPages + 1
  212.     End If
  213.     ' done
  214.     Close File
  215.     Me.MousePointer = 0
  216.     MsgBox "Filename:" + Chr(9) + CFilename + Chr$(10) + "File Size:" + Chr$(9) & FLen & Chr$(10) + "Array Pages:" + Chr$(9) & SPages & Chr$(10) + "Created Pages:" + Chr$(9) & PageGuess, 64, "Text File Loaded"
  217.     ' call the procedure that displays pages and
  218.     ' sets menu options
  219.     '
  220.     ' note: pages are numbered 1 to SPages
  221.     SetCurrentPage 1
  222.     GoTo OpenExit
  223. ' ================================================================
  224. ReadError:
  225.     MsgBox "Unable to Read file '" & CFilename & "'." + Chr$(10) + Error$, 16, "File Open Error"
  226.     Close File
  227.     Resume OpenExit
  228. ' ================================================================
  229. OpenError:
  230.     MsgBox "Unable to Open file '" & CFilename & "'." + Chr$(10) + Error$, 16, "File Open Error"
  231.     Resume OpenExit
  232. ' ================================================================
  233. OpenCancel:
  234.     Resume OpenExit
  235. ' ================================================================
  236. OpenExit:
  237.     On Error GoTo 0
  238. End Sub
  239. Sub mnuFirst_Click ()
  240.     SetCurrentPage 1
  241. End Sub
  242. Sub mnuLast_Click ()
  243.     SetCurrentPage SPages
  244. End Sub
  245. Sub mnuNext_Click ()
  246.     SetCurrentPage CurrentPage + 1
  247. End Sub
  248. Sub mnuPrev_Click ()
  249.     SetCurrentPage CurrentPage - 1
  250. End Sub
  251. '=============================================================
  252. '=  Created:    05/20/95 at 11:04 AM
  253. '=  Project:    VIEWSTR.MAK
  254. '=  Author:     Greg Truesdell
  255. '=============================================================
  256. '=  Purpose:    Set the MainView.Text to current ArrayStr
  257. '=              page of text.
  258. '=              Enable/Disable appropriate menu options.
  259. '=  Parameters: Unary-based page number (1 to SPages)
  260. '=              Page 0 is used to reset the menu
  261. '=  Returns:    N/A
  262. '=============================================================
  263. Sub SetCurrentPage (page As Integer)
  264.     CurrentPage = page
  265.     Select Case page
  266.     Case Is < 1
  267.         Status.Caption = ""
  268.         mnuFirst.Enabled = False
  269.         mnuNext.Enabled = False
  270.         mnuPrev.Enabled = False
  271.         mnuLast.Enabled = False
  272.         Exit Sub
  273.     Case 1
  274.         mnuFirst.Enabled = False
  275.         mnuNext.Enabled = (SPages > 1)
  276.         mnuPrev.Enabled = False
  277.         mnuLast.Enabled = (SPages > 1)
  278.     Case SPages
  279.         mnuFirst.Enabled = (SPages > 1)
  280.         mnuNext.Enabled = False
  281.         mnuPrev.Enabled = (SPages > 1)
  282.         mnuLast.Enabled = False
  283.     Case Else
  284.         mnuFirst.Enabled = (SPages > 1)
  285.         mnuNext.Enabled = (page < SPages)
  286.         mnuPrev.Enabled = (SPages > page)
  287.         mnuLast.Enabled = True
  288.     End Select
  289.     MainView.Text = GetArrayStr(SHandle, page - 1)
  290.     Status.Caption = "Page " & page & " of " & SPages
  291. End Sub
  292.